﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MM.Common.DBBase
{
    public class LogService
    {
        // Fields
        protected LogBase _log;
        internal static readonly LogService Instance = new LogService();

        // Methods
        protected LogService()
        {
            this.InitLog();
        }

        protected internal LogService(string name)
        {
            this.InitLog(name);
        }

        protected void InitLog()
        {
            this.InitLog("");
        }

        protected void InitLog(string name)
        {
            this.InitLog(name, "", "");
        }

        protected void InitLog(string name, string objname)
        {
            this.InitLog(name, objname, "");
        }

        protected void InitLog(string name, string objname, string evename)
        {
            this._log = new LocalLogger(name, objname, evename);
            this._log.EnableLog = true;
            this._log.EnableExp = true;
        }

        public void WriteExp(Exception ex)
        {
            string format = "ExceptionType:{0};Message:{1};Source:{2};StackTrace{3};";
            format = string.Format(format, new object[] { ex.GetType(), ex.Message, ex.Source, ex.StackTrace });
            this._log.WriteExp<string>(format);
        }

        public void WriteExp(string expinfo)
        {
            this._log.WriteExp<string>(expinfo);
        }

        public void WriteExp<T>(T expinfo)
        {
            this._log.WriteExp<T>(expinfo);
        }

        public void WriteExp(string objectname, string eventname, string expinfo)
        {
            this._log.WriteExp(objectname, eventname, expinfo);
        }

        public void WriteLog(string loginfo)
        {
            this._log.WriteLog<string>(loginfo);
        }

        public void WriteLog<T>(T loginfo)
        {
            this._log.WriteLog<T>(loginfo);
        }

        public void WriteLog(LogType type, string loginfo)
        {
            this._log.WriteLog(type, loginfo);
        }
    }
}
